#include <grp.h>

struct group *getgrnam(const char *name);//根据组名获得组信息

struct group *getgrgid(gid_t gid);//根据组ID获得组信息

描述：

The getgrnam() function returns a pointer to a structure containing the broken-out  fields of the record in the group database (e.g., the local group file /etc/group, NIS, and LDAP) that matches the group name name.

The getgrgid() function returns a pointer to a structure containing the broken-out fields of the record in the group database that matches  thegroup ID gid.

返回值：

The group structure is defined in <grp.h> as follows:

    struct group { 
        char   *gr_name;       /* group name */ 
        char   *gr_passwd;     /* group password */ 
        gid_t   gr_gid;        /* group ID */ 
        char  **gr_mem;        /* group members */ 
    };

 

4，readlink:读取软链接文件的内容

#include <unistd.h>

ssize_t readlink(const char *path, char *buf, size_t bufsiz);

描述：

DESCRIPTION 
       readlink() places the contents of the symbolic link path in the  buffer 
       buf,  which has size bufsiz.  readlink() does not append a null byte to 
       buf.  It will truncate the contents (to a length of bufsiz characters), 
       in case the buffer is too small to hold all of the contents.

RETURN VALUE 
       On  success,  readlink() returns the number of bytes placed in buf.  On 
       error, -1 is returned and errno is set to indicate the error.

示例：

复制代码
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>

#define ERR_EXIT(m) \
    do \
    { \
        perror(m); \
        exit(EXIT_FAILURE); \
    } while(0)
int main(int argc,char **argv)
{
    if(argc != 2){
        fprintf(stderr,"usage:%s linkfile", argv[0]);
        exit(EXIT_FAILURE);
    }

    char buf[1024];
    
    if(readlink(argv[1],buf,1024) ==-1)
        ERR_EXIT("readlink error");
    printf("the content of %s are: %s\n",argv[1],buf);
    return 0;
}
